package com.hqyj.shop.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hqyj.shop.dto.GoodsInfoDto;
import com.hqyj.shop.pojo.GoodsInfo;
import com.hqyj.shop.service.GoodsInfoService;
import com.hqyj.shop.util.ResultVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author rock
 * @since 2024-10-11 01:33:11
 */
@RestController
@RequestMapping("/goods-info")
public class GoodsInfoController {

    @Autowired
    GoodsInfoService goodsInfoService;
    //查询数据库分页
    @GetMapping("/queryPage")
    public ResultVo queryPage(GoodsInfoDto dto){

        return goodsInfoService.queryPage(dto);
    }
    //查询缓存分页
    @GetMapping("/queryCache")
    public ResultVo queryCache(GoodsInfoDto dto){

       Page<GoodsInfo> queryPage = goodsInfoService.cache(dto.getPage(),dto.getRow(),dto.getProType(),dto.getBrandId(),dto.getStartPrice(),dto.getEndPrice());
        if(queryPage.getRecords().size() > 0){
            HashMap<String,Object> map = new HashMap<>();
            //当前页集合
            map.put("list",queryPage.getRecords());
            //总条数
            map.put("total",queryPage.getTotal());
            //总页数
            map.put("totalPage",queryPage.getPages());
            return ResultVo.success(map);
        }
        return ResultVo.error("没有查询导数据");

        //return goodsInfoService.queryCachePage(dto);
    }
    //全文搜素分页缓存
    @GetMapping("/queryFull")
    public ResultVo queryFull(int page,int row,String word){

        Page<GoodsInfo> queryPage = goodsInfoService.cacheFull(page,row,word);
        if(queryPage.getRecords().size() > 0){
            HashMap<String,Object> map = new HashMap<>();
            //当前页集合
            map.put("list",queryPage.getRecords());
            //总条数
            map.put("total",queryPage.getTotal());
            //总页数
            map.put("totalPage",queryPage.getPages());
            return ResultVo.success(map);
        }
        return ResultVo.error("没有查询导数据");

    }

}

